<!DOCTYPE html>
<html>
  
<head>
  <meta charset="utf-8">
  <meta name="author" content="饿包子" />
  
  
  <title>对媒体查询的简单认识 | 饿包子博客</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="CSS," />
  

  
  <meta name="description" content="相信大家都知道响应式布局，也知道通过媒体查询来设置不同宽度的样式文件来适应不同屏幕的客户端。但是很多时候，对媒体查询却认识不够全面，当用到到时候，还是需要重新查阅文档，翻找文章。很多时候都是因为对其对认识不够深刻。">

  
  
    <link rel="icon" href="/blog/images/xian.ico">
    <link rel="apple-touch-icon" href="/blog/images/Logo.png">
  

  
<link rel="stylesheet" href="/blog/css/Awesome.min.css">


  
<link rel="stylesheet" href="/blog/css/index.css">
<link rel="stylesheet" href="/blog/styles/components/highlight/highlight.css">


  
  
<script src="/blog/common/jquery.min.js"></script>

  
    
<script src="/blog/common/Av.min.js"></script>

  

  
    
<script src="/blog/common/MathJax.js"></script>

  

  
    
<script src="/blog/common/Valine.min.js"></script>

  

  

  <script>
  // theme-ad's config script
  // it can be used in every script
  
  window.AD_CONFIG = {
    leancloud: {"appid":"gE1EosDsVgB2slV4E92yPkcG-gzGzoHsz","appkey":"niR787UVTMyJQrR6gmOiJCKe","comment":true,"count":true},
    welcome: {"enable":false,"interval":30},
    start_time: "2018-06-10",
    passwords: ["a621ab606db2a11f63edc576a729843b8269250dc324206871d90635ac5e531c", ],
    is_post: true,
    lock: false,
    author: "饿包子",
    share: {"twitter":false,"facebook":false,"weibo":true,"qq":true,"wechat":false},
    mathjax: true,
    page_type: "",
    root: "/blog/"
  };
</script>

  
<script src="/blog/vendor/sha256.min.js"></script>
<script src="/blog/js/auth.js"></script>
<script src="/blog/js/index.js"></script>
<script src="/blog/vendor/qrcode.min.js"></script>


<meta name="generator" content="Hexo 5.4.2"></head>
  <body>
    <header class="site-header">
  <div class="site-header-brand">
    
      <span class="site-header-brand-title">
        <a href="/blog/">清风逐月</a>
      </span>
    
    
      <span class="site-header-brand-motto"> | 我思故我在</span>
    
  </div>
  <div class="site-header-right">
    <nav class="site-header-navigation">
      
        <a href="/blog/" target="_self">主页</a>
      
        <a href="/blog/archives/" target="_self">归档</a>
      
        <a href="/blog/tags/" target="_self">标签</a>
      
        <a href="/blog/categories/" target="_self">分类</a>
      
        <a href="/blog/categories/%E6%97%A5%E8%AE%B0" target="_self">日记</a>
      
    </nav>
    <div class="site-header-btn">
      
        <a href="https://github.com/lixianbin1/" target="_blank" id="site-github">
          <i class="fa fa-github-alt"></i>
        </a>
      
      <a href="javascript:void(0);" id="site-search">
        <i class="fa fa-search"></i>
      </a>
      <a href="javascript:void(0);" id="site-nav-btn">
        <i class="fa fa-ellipsis-v"></i>
      </a>
    </div>
  </div>
</header>
<nav class="table-content" id="site-nav">
  <div class="table-content-title">
    <span>导航</span>
  </div>
  <div class="table-content-main">
    <ol class="toc">
      
        <li class="toc-item">
          <a href="/blog/" target="_self">
            主页
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/archives/" target="_self">
            归档
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/tags/" target="_self">
            标签
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/categories/" target="_self">
            分类
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/categories/%E6%97%A5%E8%AE%B0" target="_self">
            日记
          </a>
        </li>
      
    </ol>
  </div>
</nav>
<div id="site-process"></div>
    <main>
      
  <div class="passage">
  <div class="passage-meta">
    <span>
      <i class="fa fa-calendar"></i>2019-11-25
    </span>
    
    
      <span>
        | <i class="fa fa-unlock-alt"></i>UNLOCK
      </span>
    
    <span>
       | <i class="fa fa-calendar"></i>更新时间:2019-11-26 10:45 
    </span>
  </div>
  <h1 class="passage-title">
    对媒体查询的简单认识
  </h1>
  
  <article class="passage-article">
    <p>相信大家都知道响应式布局，也知道通过媒体查询来设置不同宽度的样式文件来适应不同屏幕的客户端。但是很多时候，对媒体查询却认识不够全面，当用到到时候，还是需要重新查阅文档，翻找文章。很多时候都是因为对其对认识不够深刻。</p>
<h2 id="媒体类型"><a href="#媒体类型" class="headerlink" title="媒体类型"></a>媒体类型</h2><p>在很多时候，当看到媒体查询我们都会潜意识认为它只是用来适配手机和PC的，但是这是不全面的。还有一种客户端总是被忽视的，那就是打印部分。通过媒体类型，我们首先应该设置的是计算机彩屏和打印黑白屏的区分（这也是以防万一，万一有需要要打印网页或者其他）。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- 计算机彩屏 --&gt;</span><br><span class="line">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;site.css&quot; media=&quot;screen&quot; /&gt;</span><br><span class="line"></span><br><span class="line">&lt;!-- 打印预览或打印 --&gt;</span><br><span class="line">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;print.css&quot; media=&quot;print&quot; /&gt;</span><br></pre></td></tr></table></figure>
<p>或者</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//屏幕宽度最小是800px的打印机</span><br><span class="line">@media print and (min-width: 800px) &#123; ... &#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>all —用于所有类型</li>
<li>print -用于打印机和打印预览</li>
<li>screen 电脑屏幕，手机及智能端</li>
<li>speech 用于屏幕阅读器等发声设备</li>
</ul>
<ul>
<li>其他类型(tv,aural,braille等)大多已经废弃</li>
</ul>
<h2 id="查询规则"><a href="#查询规则" class="headerlink" title="查询规则"></a>查询规则</h2><p>相信大家都是用css媒体查询来匹配对应的客户端，当然用插件自动生成也很方便。</p>
<p>关键字 <code>and</code>(且) <code>or</code>(或) <code>not</code>(非)</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">//屏幕宽度最小是800px的所有类型(当然all 是默认值)的客户端</span><br><span class="line">@media all and (min-width: 800px) &#123; ... &#125;</span><br><span class="line">@media (min-width: 800px) &#123; ... &#125;</span><br><span class="line"></span><br><span class="line">//屏幕宽度最小800px且最大1200px的所有类型的客户端</span><br><span class="line">@media (min-width:800px) and (max-width:1200px) &#123; ... &#125;</span><br><span class="line"></span><br><span class="line">//屏幕宽度最小800px或方向是纵向的所有类型的客户端</span><br><span class="line">@media (min-width:800px) or (orientation:portrait) &#123; ... &#125;</span><br><span class="line"></span><br><span class="line">//屏幕宽度最小不是800px的所有类型的客户端</span><br><span class="line">@media (not min-width:800px)&#123; ... &#125;</span><br></pre></td></tr></table></figure>

<p>屏幕方向 <code>orientation</code></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">//横向模式</span><br><span class="line">@media (orientation: landscape) &#123; ... &#125;</span><br><span class="line"></span><br><span class="line">//纵向模式</span><br><span class="line">@media (orientation: portrait) &#123; ... &#125;</span><br></pre></td></tr></table></figure>

<h2 id="媒体属性"><a href="#媒体属性" class="headerlink" title="媒体属性"></a>媒体属性</h2><p>媒体属性有很多，但最常用的还是屏幕宽度或高度等大小相关的属性，当然也有很多冷门属性，平时用不到的</p>
<table>
<thead>
<tr>
<th>属性值</th>
<th align="left">功能描述</th>
</tr>
</thead>
<tbody><tr>
<td>width</td>
<td align="left">输出设备中的页面可见区域宽度</td>
</tr>
<tr>
<td>height</td>
<td align="left">输出设备中的页面可见区域高度</td>
</tr>
<tr>
<td>min-width</td>
<td align="left">输出设备中的页面最小可见区域宽度</td>
</tr>
<tr>
<td>min-height</td>
<td align="left">输出设备中的页面最小可见区域高度</td>
</tr>
<tr>
<td>max-width</td>
<td align="left">输出设备中的页面最大可见区域宽度</td>
</tr>
<tr>
<td>max-height</td>
<td align="left">输出设备中的页面最大可见区域高度</td>
</tr>
<tr>
<td>aspect-ratio</td>
<td align="left">输出设备中的页面可见区域宽度与高度的比率</td>
</tr>
<tr>
<td>device-width</td>
<td align="left">输出设备的屏幕可见宽度</td>
</tr>
<tr>
<td>device-height</td>
<td align="left">输出设备的屏幕可见高度</td>
</tr>
<tr>
<td>min-device-width</td>
<td align="left">输出设备的屏幕最小可见宽度</td>
</tr>
<tr>
<td>min-device-height</td>
<td align="left">输出设备的屏幕最小可见高度</td>
</tr>
<tr>
<td>max-device-width</td>
<td align="left">输出设备的屏幕最大可见宽度</td>
</tr>
<tr>
<td>max-device-height</td>
<td align="left">输出设备的屏幕最大可见高度</td>
</tr>
</tbody></table>
  </article>
  <aside class="table-content" id="site-toc">
  <div class="table-content-title">
    <i class="fa fa-arrow-right fa-lg" id="site-toc-hide-btn"></i>
    <span>目录</span>
  </div>
  <div class="table-content-main">
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AA%92%E4%BD%93%E7%B1%BB%E5%9E%8B"><span class="toc-text">媒体类型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9F%A5%E8%AF%A2%E8%A7%84%E5%88%99"><span class="toc-text">查询规则</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AA%92%E4%BD%93%E5%B1%9E%E6%80%A7"><span class="toc-text">媒体属性</span></a></li></ol>
  </div>
</aside>

  
  
    <aside class="passage-copyright">
      <div>本文作者: 饿包子</div>
      
        <div>
          原文链接: 
          <a href="" target="_blank">https://lixianbin1.github.io/blog/2019/11/25/%E5%AF%B9%E5%AA%92%E4%BD%93%E6%9F%A5%E8%AF%A2%E7%9A%84%E7%AE%80%E5%8D%95%E8%AE%A4%E8%AF%86/</a>
        </div>
      
      <div>
        版权声明: 本博客所有文章除特别声明外, 均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议. 转载请注明出处!
      </div>
    </aside>
  
  
    <div class="passage-tags">
     
      <a href="/blog/tags/CSS/"><i class="fa fa-tags"></i>CSS</a>
    
    </div>
  
</div>

    </main>
    
    
<div class="site-footer-wrapper">
<!--
  <div class="footer-top">
    <a class="left" href="/blog/2019/11/27/Hooks%E6%98%AF%E5%90%A6%E5%8F%96%E4%BB%A3Redux/" data-enable="true">
      <i class="fa fa-arrow-left"></i>
    </a>
    <a class="right" href="/blog/2019/11/05/%E6%B8%90%E8%BF%9B%E5%BC%8F%E7%BD%91%E9%A1%B5%E5%BA%94%E7%94%A8%20PWAs/" data-enable="true">
      <i class="fa fa-arrow-right"></i>
    </a>
  </div>
-->
  <footer class="site-footer">
    
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">网站推荐</h5>
          
            <span class="site-footer-item">
              <a href="https://tympanus.net/codrops/" target="_blank">Codrops</a>
            </span>
          
            <span class="site-footer-item">
              <a href="http://taobaofed.org/" target="_blank">淘宝前端团队(FED)</a>
            </span>
          
        </div>
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">文档教程</h5>
          
            <span class="site-footer-item">
              <a href="https://es6.ruanyifeng.com/" target="_blank">ES6入门</a>
            </span>
          
            <span class="site-footer-item">
              <a href="https://developer.mozilla.org/zh-CN/docs/Web" target="_blank">MDN Web文档</a>
            </span>
          
        </div>
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">兴趣前沿</h5>
          
            <span class="site-footer-item">
              <a href="https://threejs.org/" target="_blank">threejs</a>
            </span>
          
            <span class="site-footer-item">
              <a href="https://github.com/justadudewhohacks/face-api.js" target="_blank">face-api</a>
            </span>
          
        </div>
      
    
    <div class="site-footer-info">
      <i class="fa fa-clock-o"></i> 本站已稳定运行<span id="site-time"></span>
    </div>
    
      <div class="site-footer-info">
        <i class="fa fa-paw"></i> 您是本站第 <span id="site-count"></span> 位访客
      </div>
    
    
      <div class="site-footer-info">
        <i class="fa fa-at"></i> Email: xianbin.me@qq.com
      </div>
    
<!--     <div class="site-footer-info">
      <i class="fa fa-copyright"></i> 
      2019 <a href="https://github.com/dongyuanxin/theme-ad/" target="_blank">Theme-AD</a>.
      Created by <a href="https://godbmw.com/" target="_blank">GodBMW</a>.
      All rights reserved.
    </div> -->
  </footer>
</div>
    <div id="site-layer" style="display:none;">
  <div class="site-layer-content">
    <div class="site-layer-header">
      <span class="site-layer-header-title" id="site-layer-title"></span>
      <i class="fa fa-close" id="site-layer-close"></i>
    </div>
    <div class="site-layer-body" id="site-layer-container">
      <div class="site-layer-input" id="site-layer-search" style="display: none;">
        <input type="text">
        <i class="fa fa-search"></i>
      </div>
      
        <div class="site-layer-reward" id="site-layer-reward" style="display: none;">
          
            <div>
              <img src="/blog/images/wechat.png" alt="WeChat">
              
                <p>WeChat</p>
              
            </div>
          
            <div>
              <img src="/blog/images/alipay.png" alt="AliPay">
              
                <p>AliPay</p>
              
            </div>
          
        </div>
      
      <div id="site-layer-welcome" style="display:none;"></div>
    </div>
  </div>
</div>
    

<div class="bottom-bar">

  <div class="bottom-bar-left">
<!--
    <a href="/blog/2019/11/27/Hooks%E6%98%AF%E5%90%A6%E5%8F%96%E4%BB%A3Redux/" data-enable="true">
      <i class="fa fa-arrow-left"></i>
    </a>
    <a href="/blog/2019/11/05/%E6%B8%90%E8%BF%9B%E5%BC%8F%E7%BD%91%E9%A1%B5%E5%BA%94%E7%94%A8%20PWAs/" data-enable="true">
      <i class="fa fa-arrow-right"></i>
    </a>
-->
  </div>

  
  
  
  <div class="bottom-bar-right">
    <a href="javascript:void(0);" data-enable="true" id="site-toc-show-btn">
      <i class="fa fa-bars"></i>
    </a>
    
      <a href="#site-comment" data-enable="true">
        <i class="fa fa-commenting"></i>
      </a>
    
    <a href="javascript:void(0);" id="site-toggle-share-btn">
      <i class="fa fa-share-alt"></i>
    </a>
    
    <a href="javascript:void(0);" id="back-top-btn">
      <i class="fa fa-chevron-up"></i>
    </a>
  </div>
</div>
    <div id="share-btn">
  
  
  
    <a id="share-btn-weibo" href="javascript:void(0);" target="_blank">
      <i class="fa fa-weibo"></i>
    </a>
  
  
    <a id="share-btn-qq" href="javascript:void(0);" target="_blank">
      <i class="fa fa-qq"></i>
    </a>
  
  
</div>
    





    
  </body>
</html>